#第一个注释
# print("Hello, World!") #第二个注释
'''
第三行注释
第四行注释
'''
from operator import ifloordiv
from pickletools import string1

"""
第五行注释
第六行注释
"""
# print("Hello, Python!") #第七行注释

"""
if 1+1 == 3:
    print("True")
else:
    print("False")
if True:
    print("Answer")
    print("True")
else:
    print("Answer")
    print("False")
"""

"""iter_one: int = 1
iter_two: int = 2
iter_three: int = 3
total = iter_one + \
            iter_two + \
            iter_three
print(total)
print(r"this is a test \n"*2)
print("1")
input("\n\n按下enter键后退出程序...")"""

# import sys;x = 'runoob';char_write = sys.stdout.write(x+'\n')
# print(char_write)
# array = [1, 2, 4, 3, 5]
# for i in range(0,len(array)):
#     for j in range(0,len(array)-1):
#         if array[j] > array[j+1]:
#             swap = array[j]
#             array[j] = array[j+1]
#             array[j+1] = swap
#
# print(array)
# print("Hello, Python!","hhh","world!",sep=" ",end="/")
# print("sssss",end="nnnn")
# print("qqqqqq",end="\n")
#
#
# name = "Alice"
# age = 25
# print(type(name),type(age))
# flag = True
# print(type(flag))
# result = flag+False
# print(type(result))
# print(result)
# m1 = 1+2j
# m2 = 1-2j
# print(m1*m2)
# print(type(m1))
# name = "Alice"
# age = 18
# print("My name is %s and I am %d years old." % (name, age))

# num = 123
# print("%06d" % num)9
# num = 1.23456
# print("%.4f" % num)

# print("我是%%的%%" % ())

# name = "Alice"
# age = 25
# print(f"My name is {name} and I am {age} years old.")

# name = input("请输入您的姓名：")
# age = input("请输入您的年龄：")
# print(f"您的姓名是：{name}，年龄是：{age}。")

# achievements = input("请输入你的成绩：")
# if int(achievements) > 60:
#     print("奖励！")
# else:
#     print("不及格，继续努力！")
# print(not 3>9)

# score = input("请输入你的成绩：")
# if int(score) > 90:
#     print("优")
# elif 80 < int(score) <= 90:
#     print("良")
# elif 70 < int(score) <= 80:
#     print("中")
# elif 60 < int(score) <= 70:
#     print("及格")
# else:
#     print("不及格")

# i = 0
# while(i < 100):
#     i += 1
#     print(f"好好学习第{i}天")

# for i in "hello world":
#     print(i)

# for i in "123":
#     print(i)

# for i in range(1,11):
#     print(i)


# array = [2,5,9,7,4,1,6,3,16,10]
# for i in range(0,len(array)):
#     for j in range(0,len(array)-1-i):
#         if array[j] > array[j+1]:
#             temp = array[j]
#             array[j] = array[j+1]
#             array[j+1] = temp
# print(array)

"""num = 0
for i in range(1,101):
    num += i
print(num)"""

# str = "abcdefg"
# print(str[0::2])

# name_list = ["Alice", "Bob", "Charlie", "David"]
# name = input("请输入名称：")
# while name not in name_list:
#     name = input("姓名错误，请重新输入：")
# print("欢迎，" + name + "！")


# a = "hello"
# print(a,type(a))
#
# a1 = a.encode('utf-8')
# print(a1,type(a1))
#
# a2 = a1.decode('utf-8')
# print(a2,type(a2))

# dic = {'name': 'ZY','age': 22,'gender':'男'}
# print(len(dic))
# print(dic.keys())
# for key in dic.keys():
#     print(key)
# print(dic.values())
# for value in dic.values():
#     print(value,type(value))

# print(dic.items())
# for i in dic.items():
#     print(i,type(i))  # 输出元组

# s1 = {1,2,3,4,5}
# s2 = {'a','b','c','d','e',1,2,3}
# print(s1)
# print(s2)

# print(hash('a'))
# print(hash(1))
#
# print(s2)

# li = ["one", "two", "three"]
# li.append("four")
# print(li)
#
# li.extend("five")
# print(li)
#
# li.insert(len(li),"six")
# print(li)
#
# li.insert(0,"zero")
# print(li)

# li = [1,2,3]
# li[1] = 'a'
# print(li)

# li = ['a', 'b', 'a', 'd', 'e']
# print(li.count('a'))
# print(li.index('a'))
# print(li.index('a', 2))

# li = ['a', 'b', 'a', 'd', 'e']
# del li[2]
# print(li)
# li.pop()
# print(li)
# li.pop(2)
# print(li)
# li.remove('a')
# print(li)

# li = [2, 5, 9, 7, 4, 1, 6, 3, 16, 10]
# li.reverse()
# print(li)
# li.sort()
# print(li)

# li1 = []
# [li1.append(i) for i in range(1,11)]
# print(li1)
# li2 = []
# [li2.append(i) for i in range(1,11) if i%2 == 0]
# print(li2)


# li = [1,2,3,[4,5,6]]
# print(li[3])


# li = {1,2,3,4,5}
# print(type(li))

# tua = (1,2,3,'a',[4,5,6])
# print(tua,type(tua))

# tua = ()
# print(tua,type(tua))

# tua1 = ('a')
# print(tua1,type(tua1))
# tu2 = ('a',)
# print(tu2,type(tu2))

# tua = (1,2,3,1)
# print(tua[0])  #可以通过下标访问元组中的元素
# print(tua.count(1)) #统计元组中某个元素出现的次数
# print(tua.index(1)) #返回元组中某个元素的索引，如果元素重复，只返回第一次出现的索引
# print(len(tua)) #返回元组的长度
# print(tua[0:]) #元组也可进行切片操作

# name = "Alice"
# age = 25
# person = (name,age)
# print("他的名字是%s,年龄是%d" % person)
# print(type(person))

# def login(username,password):
#     if username == 'admin' and password == '123456':
#         print("登录成功")
#         return True
#     else:
#         print("登录失败")
#         return False
# username = input("请输入用户名：")
# password = input("请输入密码：")
# result = login(username,password)
# print(result,type(result))

# def func(*args): #定义一个函数，参数为任意个（可变参数）
#     print(args)
#     print(type(args))
# func("海绵宝宝","派大星","章鱼哥")
# def func1(a,b,c=0,*args): #定义一个函数，参数为必选参数a,b,可选参数c,任意个（可变参数）


#关键字参数
# def func(**kwargs):
#     print(kwargs)
#     print(type(kwargs))
# func(name="海绵宝宝",age=22,gender="男")

# dic1 = {'name': 'ZY','age': 22,'gender':'男'}
# print(dic1,type(dic1))
# dic2 = {'name': 'Alice','name':"Bob"}
# print(dic2)
# dic3 = {'name1': 'Alice','name2':'Bob'}
# print(dic3)

# dic = {'name': 'ZY','age': 22,'gender':'男'}
#print(dic[2]) #报错，字典中没有下标，查找元素需要根据键名，键名相当于下标
# print(dic['age'])
# print(dic['sex']) 不存在，会报错

# dic = {'name': 'ZY','age': 22,'gender':'男'}
# print(dic.get('name'))
# print(dic.get('sex')) #不存在，返回None
# print(dic.get('sex','男')) #不存在，返回默认值

# dic = {'name': 'ZY','age': 22,'gender':'男'}
# dic['name'] = 'Alice'
# print(dic)

# dic = {'name': 'ZY','age': 22}
# print(dic)
# dic['gender'] = '男'
# print(dic)
# dic['gender'] = '女'
# print(dic)

# dic = {'name': 'ZY','age': 22,'gender':'男'}
# print(dic)
# del dic['age']
# print(dic)
# #del dic #删除字典，会报错
# #del dic['sex'] #删除不存在的键，会报错
# dic.clear() #清空字典，但不会删除字典变量
# print(dic)
# dic = {'name': 'ZY','age': 22,'gender':'男'}
# print(dic)
# dic.pop('age')
# print(dic)
# #dic.pop('sex') #删除不存在的键，会报错
# print(dic.popitem()) #随机删除字典中的一对键值对，并返回该对键值对,3.7版本后默认删除最后一对键值对
# print(dic)

#普通函数
# def add(a,b):
#     return a+b
# print(add(1,2))
#lambda函数
# add_lambda = lambda a,b:a+b
# print(add_lambda(3,4))



# dic = {'name': 'ZY','age': 22,'gender':'男'}
# print(len(dic))

# dic = {'name': 'ZY','age': 22,'gender':'男'}
#
# print(dic.keys())
# for key in dic.keys():
#     print(key,type(key))
#
# print(dic.values())
# for  value in  dic.values():
#     print(value,type(value))

# dic = {'name': 'ZY','age': 22,'gender':'男'}
# print(dic.items(),type(dic.items()))
# for i in dic.items():
#     print(i,type(i))  # 输出元组

# s1 = {1,2,3,4,5}
# s2 = {'a','b','c','d','e',1,2,3} #集合具有无序性，每次运行结果都不一样
# print(s1)
# print(s2)
#
# s3 = {} #这里是定义一个空的字典
# print(s3,type(s3))
#
# s4 = set() #这里是定义一个空的集合
# print(s4,type(s4))


# print(hash(1))
# print(hash('a'))
# print(hash('1'))

# s1 = {1,2,3,1,2}
# print(s1)

# s1 = {1,2,3}
# print(s1)
# s1.add(4)
# print(s1)
# s1.add(4) #集合中不允许有重复元素，重复元素会自动忽略
# print(s1)
# #s1.add(5,6) 不可以一次性添加多个元素

# s1 = {1,2,3}
# print(s1)
# s1.update([4,5,6])
# print(s1)
# s1.update((7,8,9))
# print(s1)
# s1.update({10,11,12})
# print(s1)
# s1.update("hello")
# print(s1)

# s1 = {1,2,3,4,5}
# print(s1)
# s1.remove(3)
# print(s1)
#s1.remove(6) 删除集合中不存在的元素，会报错

# s1 = {'a','b','c','d','e'}
# print(s1)
# s1.pop()
# print(s1)
# #s1.pop() #删除集合中最后一个元素，并返回该元素


# s1 = {1,2,3,4,5}
# print(s1)
# s1.discard(1)
# print(s1)
# s1.discard(6) #删除集合中不存在的元素，不会报错
# print(s1)

# s1 = {1,2,3,4,5}
# s2 = {4,5,6,7,8}
# print(s1 & s2 ) #求两个集合的并集
# print(s1 | s2 ) #求两个集合的并集
#
# s3 = {1,2,3}
# s4 = {4,5,6}
# print(s3 & s4)

# a = 10
# b = 20
# print("a > b") if a > b else print("a < b")


# lambda_func = lambda x:x+1
# print(lambda_func(10))

# import builtins
# print(dir(builtins))

# print(abs(-10))
# print(sum([1,2,3,4,5]))
# print(min(1,3.3))
# print(max(1,3.3))
# print(min([1,-3,5,-7,9],key=abs))

# li = [1,2,3]
# li2 = ['a','b','c']
# print(zip(li,li2))
# for i in zip(li,[3,4,5]):
#     print(i)

# li1 = [1,2,3,4,5]
# li2 = li1
# print(li1)
# print(li2)
# li1.append(6)
# print(li1,id(li1))
# print(li2,id(li2))

# import copy
# li1 = [1,2,[3,4,5]]
# li2 = copy.copy(li1)
# print(li1)
# print(li2)
# li1.append(6)
# print(li1,id(li1))
# print(li2,id(li2))
# li1[2].append(7)
# print(li1,id(li1[2]))
# print(li2,id(li2[2]))

# import copy
# li1 = [1,2,[3,4,5]]
# li2 = copy.deepcopy(li1)
# print("li1:",li1,id(li1))
# print("li2:",li2,id(li2))
# li1[2].append(6)
# print("li1:",li1,id(li1[2]))
# print("li2:",li2,id(li2[2]))
# li1.append(7)
# print("li1:",li1,id(li1))
# print("li2:",li2,id(li2))


# def func():
#     print("hello world")
# func()
# func()


# def buy():
#     print("小姐，请问有没有半岛铁盒？")
#     return "有啊，你从前面右转的第二排架子上就有了"
# print(buy())

# def buy():
#     print("小姐，请问有没有半岛铁盒？")
#     return "有啊，你从前面右转的第二排架子上就有了"
#     return "没有" #函数中只能有一个return语句，多余的return语句不会被执行
# print(buy())

# def add(a,b):
#     return a+b
# print(add(1,2))


# def func(name,age,gender):
#     print("姓名:"+name)
#     print("年龄:"+str(age))
#     print("性别:"+gender)
# func("张三",25,"男")
# print("----------------")
# func("女",30,"张三")

# def func(a=12):
#     print(a)
# func()
# func(34)
# func(a=56)

# def func(b,a=18):
#     print(a)
#     print(b)
# func(20) #只传一个值的时候，传给的不是默认参数
# func(25,19)

# def func(*args):
#     print(args)
#     print(type(args))   #以元组形式接收
# func(1)
# func("海绵宝宝","派大星","章鱼哥")

# def func(**kwargs):
#     print(kwargs)
#     print(type(kwargs))   #以字典形式接收
# func() #空字典
# func(name="海绵宝宝",age=22,gender="男")
#作用：可以扩展函数功能，可以接收任意数量的关键字参数，并将其作为字典传入函数中


# def study():
#     print("学习")
# def course():
#     study()
#     print("Python课程")
# course()

# def study():
#     print("学习")
#     def course():
#         print("Python课程")
#     course() #注意，定义和调用的顺序以及缩进，定义和调用是同级的，调用如果在定义里面，则永远也调用不到
# study()

#普通函数
# def add(a,b):
#     return a+b
# print(add(1,2))
# #lambda函数（匿名函数）
# add_lambda = lambda a,b:a+b
# print(add_lambda(3,4))

# funa = lambda :"爷爷泡的茶"
# print(funa())
# funb = lambda x:x+1
# print(funb(10))


# func = lambda a,b,c=18:a+b+c
# print(func(10,20))
# print(func(10,20,30))

# fund = lambda **kwargs:kwargs
# print(fund(name="海绵宝宝",age=22,gender="男"))

# a = 11
# b = 22
# print("a比b大") if a > b else print("a比b小")
# #使用lmabda表达式
# campare = lambda a,b: "a比b大" if a > b else "a比b小"
# print(campare(11,22))


# def function():
#     print("hello world")
#     raise Exception("抛出异常")
# function()


# def login():
#     password = input("请输入密码：")
#     if len(password) < 6:
#         raise Exception("密码长度不能小于6位")
#     else:
#         print("密码长度正确")
# try:
#     print(login())
# except Exception as e:
#     print(e)


# def add(n):
#     if n <= 1:
#         return n
#     return add(n-2)+add(n-1)
#a(1)+a(2)
#1+a(0)+a(1)
#
# print(add(3))

# a = 1
# print(id(a))
# a = 2
# print(id(a))
# print(id(2))
# print(id(1))


# def login():
#     print("登录中...")
# def func(fn):
#     def inner():
#         print("注册中...")
#         fn()
#     return inner
# oc = func(login)
# oc()

# def func(fn):
#     def inner():
#         print("召唤马克5号中...")
#         fn()
#     return inner
#
# @func
# def fly():
#     def inner():
#         print("马克5号飞行中...")
#     return inner
# fly()

# import builtins
# print(dir(builtins))
# #大写字母开头一般是内置常量名，小写

# print(abs(-10))
# #print(sum(123)) 必须是可迭代对象
# #print(sum({'name':'张三','age':25,'gender':'男'})) 字符串、字典不能求和
# print(sum({1,2,3})) #集合求和
# print(sum([1,2,3,4,5])) #列表求和
# print(sum((1,2,3))) #元组求和
# print(sum((1,3.3))) #有浮点数相加则结果也是浮点数

# print(min(1,3,4))
# print(max(1,3,4))
# print(min(-8,5))
# print(min(-8,5,key=abs))  #先求绝对值然后求最小值

# li1 = [1,2,3]
# li2 = ['a','b','c']
#
# #循环打印
# for i in zip(li1,li2):
#     print(i)
# #列表化打印
# print(list(zip(li1,li2)),type(zip(li1,li2)))

# def add(a,b):
#     return a+b
# li = [1,2,3,4,5]
# #需要先导包
# from functools import reduce
# #reduce（function,sequence） function--函数:必须是有两个参数的函数，sequence是序列：可迭代对象
# # 连续的两个元素作为参数，返回一个值，最后返回一个值。
# print(reduce(add,li)) #求和

tua = (1,2,3,4,5)
print(tua)
print(tua[2])

#方法一
#要求元组内的个数和接受的变量个数相同，对象中有几个元素，就定义几个变量去接受，否则会报错
#一般在获取元组内的值的时候使用
a,b,c,d,e = tua
print("方法一",'a=',a,'b=',b,'c=',c,'d=',d,'e=',e)

#方法二
#先把单独的取完，然后剩下的数据全部放入带*的变量中
a,*b = tua
print("方法二",'a=',a,'b=',b)
#一般在函数调用的时候使用
def func(a,b,*args):
    print(a,b)
    print(args,type(args))
func(1,2,3,4,5)
arg = (1,2,3,4,5)
func(*arg)
